//
//  UIBarButtonItem+Externsion.swift
//  ZMWeiboSwift
//
//  Created by pg on 2017/7/22.
//  Copyright © 2017年 pg. All rights reserved.
//

import UIKit

//分类中等重写指定构造函数,,不能定义存储属性
extension UIBarButtonItem{
    
    
    //重写构造函数
    convenience init(title:String,imageName:String? = nil ,target:Any?,action:Selector) {
        
        
        //定义按钮
        let btn = UIButton(type: .custom)
        //设置标题
        btn.setTitle(title, for: .normal)
        //添加单击事件
        btn.addTarget(target, action: action, for: .touchUpInside)
        //设置图片
        if imageName != nil {
            btn.setImage(UIImage(named:imageName!), for: UIControlState.normal)
        }
        
        //设置文字的颜色和字体大小
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        btn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        btn.setTitleColor(UIColor.orange, for: UIControlState.highlighted)
        //设置按钮大小自动适应
        btn.sizeToFit()
        
        
        self.init(customView: btn)
    }
    
}

